package com.baofu.paycore.service.converter;

import com.alibaba.fastjson.JSON;
import com.baofu.paycore.dal.model.ClearDO;
import com.baofu.paycore.dal.model.TransferDO;
import com.baofu.paycore.manager.model.*;
import com.baofu.paycore.manager.model.preAuth.PreAuthBO;
import com.baofu.paycore.manager.model.preAuth.SubPreAuthBO;
import com.baofu.paycore.manager.model.withdraw.WithdrawBO;
import com.baofu.paycore.manager.model.withdraw.WithdrawBankBO;
import com.baofu.paycore.manager.util.PaymentInfoUtils;
import com.baofu.paycore.service.facade.enums.PayStatusEnums;
import com.baofu.paycore.service.facade.enums.PayToolTypeEnum;
import com.baofu.paycore.service.facade.model.AccountFreeze.FreezeDTO;
import com.baofu.paycore.service.facade.model.AccountFreeze.UnfreezeDTO;
import com.baofu.paycore.service.facade.model.CancelPayDTO;
import com.baofu.paycore.service.facade.model.PayBaseDTO;
import com.baofu.paycore.service.facade.model.PayPageQueryReqDTO;
import com.baofu.paycore.service.facade.model.authconfirm.AuthConfirmDTO;
import com.baofu.paycore.service.facade.model.authorize.AuthorizeDTO;
import com.baofu.paycore.service.facade.model.authorize.AuthorizeFundDTO;
import com.baofu.paycore.service.facade.model.pay.FundDetailInfoDTO;
import com.baofu.paycore.service.facade.model.pay.PayDTO;
import com.baofu.paycore.service.facade.model.recharge.RechargeDTO;
import com.baofu.paycore.service.facade.model.refund.req.RefundReqDTO;
import com.baofu.paycore.service.facade.model.withdraw.UnfreezeWithdrawDTO;
import com.baofu.paycore.service.facade.model.withdraw.WithDrawFundDTO;
import com.baofu.paycore.service.facade.model.withdraw.WithdrawDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;
import org.slf4j.helpers.SystemMarker;

import java.math.BigDecimal;

/**
 * BO转换成DTO对象
 * <p>
 *     1、充值接口返回结果信息处理
 * </p>
 * User: kwl  Date: 16/5/7 ProjectName: paycore Version: 5.0.0
 */
@Slf4j
public class DTO2BOConverter {

    /**
     * 充值请求对象DTO转BO
     *
     * @param rechargeDTO    充值请求DTO对象
     * @param rechargeBO     充值请求BO对象
     */
    public static void rechargeDTO2BO(RechargeDTO rechargeDTO, RechargeBO rechargeBO) {

        rechargeBO.setRelationNo(rechargeDTO.getRelationNo());
        rechargeBO.setRequestOrderNo(rechargeDTO.getRequestOrderNo());
        rechargeBO.setRequestSystem(rechargeDTO.getRequestSystem());
        rechargeBO.setRequestDate(rechargeDTO.getRequestDate());
        rechargeBO.setRequestBizNo(rechargeDTO.getRequestBizNo());
        rechargeBO.setRequestChannel(rechargeDTO.getRequestChannel());

        rechargeBO.setBizType(rechargeDTO.getBizType());
        rechargeBO.setSubBizType(rechargeDTO.getSubBizType());

        rechargeBO.setAccountNo(rechargeDTO.getAccountNo());
        rechargeBO.setContractNo(rechargeDTO.getContractNo());
        rechargeBO.setProductChannel(rechargeDTO.getProductChannel());

        rechargeBO.setCcy(rechargeDTO.getCcy());
        rechargeBO.setAmt(rechargeDTO.getAmt());
        //支付单状态
        rechargeBO.setStatus(PayStatusEnums.INIT.getCode());

        //付款方信息
        rechargeBO.setPaymentInfo(JSON.toJSONString(rechargeDTO.getPaymentExt()));
        rechargeBO.setPaymentExt(rechargeDTO.getPaymentExt());

        rechargeBO.setDescription(rechargeDTO.getDescription());
        rechargeBO.setMerchantNo(rechargeDTO.getMerchantNo());
        rechargeBO.setServiceCode(rechargeDTO.getServiceCode());
        rechargeBO.setOperator(rechargeDTO.getOperator());
        rechargeBO.setReturnUrl(rechargeDTO.getReturnUrl());
    }

    /**
     * 充值请求对象DTO转BO
     *
     * @param rechargeDTO    充值请求DTO对象
     * @param rechargeBO     充值请求BO对象
     */
    public static RechargeBankBO rechargeBankBOConverter(RechargeDTO rechargeDTO, RechargeBO rechargeBO){

        RechargeBankBO rechargeBankBO = new RechargeBankBO();
        if(null == rechargeDTO){
            return rechargeBankBO;
        }

        rechargeBankBO.setPayNo(rechargeBO.getPayNo());
        rechargeBankBO.setCcy(rechargeDTO.getCcy());
        rechargeBankBO.setAmt(rechargeDTO.getAmt());
        rechargeBankBO.setStatus(PayStatusEnums.INIT.getCode());
        rechargeBankBO.setDescription(rechargeDTO.getDescription());
        if(null != rechargeDTO.getFundBaseDTO()){
            rechargeBankBO.setChargeFee(rechargeDTO.getFundBaseDTO().getBizChargeAmount());
            rechargeBankBO.setPayToolType(rechargeDTO.getFundBaseDTO().getPayToolType());
            rechargeBankBO.setPayToolSubType(rechargeDTO.getFundBaseDTO().getPayToolSubType());

            rechargeBankBO.setContractNo(rechargeDTO.getContractNo());
            rechargeBankBO.setAgreementNo(rechargeDTO.getFundBaseDTO().getAgreementNo());
            rechargeBankBO.setAgreeRelId(rechargeDTO.getFundBaseDTO().getAgreeRelId());
            rechargeBankBO.setCardType(rechargeDTO.getFundBaseDTO().getCardType());
            rechargeBankBO.setBankCode(rechargeDTO.getFundBaseDTO().getBankCode());
            rechargeBankBO.setOpFlag(rechargeDTO.getFundBaseDTO().getOpFlag());
        }

        return rechargeBankBO;
    }

    /**
     * 提现请求对象DTO转BO
     *
     * @param withdrawDTO    提现请求DTO对象
     * @param withdrawBO     提现请求BO对象
     */
    public static void withdrawDTO2BO(WithdrawDTO withdrawDTO, WithdrawBO withdrawBO){

        withdrawBO.setRelationNo(withdrawDTO.getRelationNo());
        withdrawBO.setRequestOrderNo(withdrawDTO.getRequestOrderNo());
        withdrawBO.setRequestSystem(withdrawDTO.getRequestSystem());
        withdrawBO.setRequestDate(withdrawDTO.getRequestDate());
        withdrawBO.setRequestBizNo(withdrawDTO.getRequestBizNo());
        withdrawBO.setRequestChannel(withdrawDTO.getRequestChannel());


        withdrawBO.setBizType(withdrawDTO.getBizType());
        withdrawBO.setSubBizType(withdrawDTO.getSubBizType());

        withdrawBO.setAccountNo(withdrawDTO.getAccountNo());
        withdrawBO.setContractNo(withdrawDTO.getContractNo());

        withdrawBO.setCcy(withdrawDTO.getCcy());
        withdrawBO.setAmt(withdrawDTO.getAmt());
        withdrawBO.setMerchantNo(withdrawDTO.getMerchantNo());
        withdrawBO.setServiceCode(withdrawDTO.getServiceCode());
        //支付单状态
        withdrawBO.setStatus(PayStatusEnums.INIT.getCode());

        withdrawBO.setDescription(withdrawDTO.getDescription());
        withdrawBO.setBankCode(withdrawDTO.getBankCode());
        withdrawBO.setOperator(withdrawDTO.getOperator());
        withdrawBO.setTradeLogId(MDC.get(SystemMarker.TRACE_LOG_ID));
    }
    /**
     * 提现请求对象DTO转BO
     *
     * @param withdrawDTO    提现请求DTO对象
     * @param withdrawBO     提现请求BO对象
     */
    public static void withdrawDTO2BO(UnfreezeWithdrawDTO withdrawDTO, WithdrawBO withdrawBO){

        withdrawBO.setRelationNo(withdrawDTO.getRelationNo());
        withdrawBO.setRequestOrderNo(withdrawDTO.getRequestOrderNo());
        withdrawBO.setRequestSystem(withdrawDTO.getRequestSystem());
        withdrawBO.setRequestDate(withdrawDTO.getRequestDate());
        withdrawBO.setRequestBizNo(withdrawDTO.getRequestBizNo());
        withdrawBO.setRequestChannel(withdrawDTO.getRequestChannel());


        withdrawBO.setBizType(withdrawDTO.getBizType());
        withdrawBO.setSubBizType(withdrawDTO.getSubBizType());

        withdrawBO.setAccountNo(withdrawDTO.getAccountNo());
        withdrawBO.setContractNo(withdrawDTO.getContractNo());
        withdrawBO.setOldPayNo(withdrawDTO.getOrigPayNo());

        withdrawBO.setCcy(withdrawDTO.getCcy());
        withdrawBO.setAmt(withdrawDTO.getAmt());
        withdrawBO.setMerchantNo(withdrawDTO.getMerchantNo());
        withdrawBO.setServiceCode(withdrawDTO.getServiceCode());
        //支付单状态
        withdrawBO.setStatus(PayStatusEnums.INIT.getCode());

        withdrawBO.setDescription(withdrawDTO.getDescription());
        withdrawBO.setOperator(withdrawDTO.getOperator());
        withdrawBO.setTradeLogId(MDC.get(SystemMarker.TRACE_LOG_ID));
    }

    /**
     * 提现请求对象DTO转BO
     *
     * @param withdrawDTO    提现请求DTO对象
     * @param withdrawBO     提现请求BO对象
     */
    public static WithdrawBankBO withdrawBankBOConverter(WithdrawDTO withdrawDTO, WithdrawBO withdrawBO){

        WithdrawBankBO withdrawBankBO = new WithdrawBankBO();
        if(null == withdrawDTO){
            log.error("提现请求对象DTO转BO withdrawDTO对象为空");
            return withdrawBankBO;
        }

        withdrawBankBO.setPayNo(withdrawBO.getPayNo());
        withdrawBankBO.setCcy(withdrawDTO.getCcy());
        withdrawBankBO.setAmt(withdrawDTO.getAmt());
        withdrawBankBO.setStatus(PayStatusEnums.INIT.getCode());
        withdrawBankBO.setDescription(withdrawDTO.getDescription());
        withdrawBankBO.setCardType(withdrawDTO.getCardType());
        withdrawBankBO.setBankCode(withdrawDTO.getBankCode());
        withdrawBankBO.setPayToolType(PayToolTypeEnum.BANK_CARD.getCode());
        withdrawBankBO.setDescription(withdrawDTO.getDescription());
        withdrawBankBO.setContractNo(withdrawDTO.getContractNo());
        WithDrawFundDTO withDrawFundDTO = withdrawDTO.getWithDrawFundDTO();
        if(null != withDrawFundDTO){
            withdrawBankBO.setAgreementNo(withDrawFundDTO.getAgreementNo());
            withdrawBankBO.setAgreeRelId(withDrawFundDTO.getAgreeRelId());
        }
        return withdrawBankBO;
    }

    /**
     * 提现请求对象DTO转BO
     *
     * @param withdrawDTO    提现请求DTO对象
     * @param withdrawBO     提现请求BO对象
     */
    public static WithdrawBankBO withdrawBankBOConverter(UnfreezeWithdrawDTO withdrawDTO, WithdrawBO withdrawBO){

        WithdrawBankBO withdrawBankBO = new WithdrawBankBO();
        if(null == withdrawDTO){
            log.error("提现请求对象DTO转BO withdrawDTO对象为空");
            return withdrawBankBO;
        }

        withdrawBankBO.setPayNo(withdrawBO.getPayNo());
        withdrawBankBO.setCcy(withdrawDTO.getCcy());
        withdrawBankBO.setAmt(withdrawDTO.getAmt());
        withdrawBankBO.setStatus(PayStatusEnums.INIT.getCode());
        withdrawBankBO.setDescription(withdrawDTO.getDescription());
        withdrawBankBO.setPayToolType(PayToolTypeEnum.BANK_CARD.getCode());
        withdrawBankBO.setDescription(withdrawDTO.getDescription());
        withdrawBankBO.setContractNo(withdrawDTO.getContractNo());
        WithDrawFundDTO withDrawFundDTO = withdrawDTO.getWithDrawFundDTO();
        if(null != withDrawFundDTO){
            withdrawBankBO.setAgreementNo(withDrawFundDTO.getAgreementNo());
            withdrawBankBO.setAgreeRelId(withDrawFundDTO.getAgreeRelId());
        }
        return withdrawBankBO;
    }
    /**
     * 退款请求对象DTO转BO
     *
     * @param refundReqDTO    退款请求DTO对象                 ,
     * @param refundBO     退款请求BO对象
     */
    public static void refundDTO2BO(RefundReqDTO refundReqDTO, RefundBO refundBO){

        payBaseBOConverter(refundReqDTO, refundBO);
        refundBO.setOrigRequestOrderNo(refundReqDTO.getOrigRequestOrderNo());
        refundBO.setOrigRequestBizNo(refundReqDTO.getOrigRequestBizNo());
        refundBO.setOrigRequestSystem(refundReqDTO.getOrigRequestSystem());
        refundBO.setOrigRequestDate(refundReqDTO.getOrigRequestDate());

        //refundBO.setPayerAccNo(refundBO.getPayerNo());
        refundBO.setHasRefundAmt(0L);
        refundBO.setHasRefundFeeAmt(0L);
        refundBO.setFeeAmt(refundReqDTO.getFreeAmt());
        if(null == refundReqDTO.getFreeAmt()){
            refundBO.setFeeAmt(0L);
        }
        refundBO.setRefundFeeAmt(refundReqDTO.getRefundFeeAmt());
        if(null == refundReqDTO.getRefundFeeAmt()){
            refundBO.setRefundFeeAmt(0L);
        }
        refundBO.setStatus(PayStatusEnums.INIT.getCode());

        //refundBO.setRefundType(refundReqDTO.getRefundType());
        refundBO.setSourceCcy(refundReqDTO.getSourceCcy());
        refundBO.setSourceAmt(refundReqDTO.getSourceAmt());
        refundBO.setRate(new BigDecimal(refundReqDTO.getRate()));
        refundBO.setRefundExtra(refundReqDTO.getRefundExtra());
    }

    /**
     * 支付请求BO对象
     *
     * @param payBaseDTO    支付请求DTO对象
     * @param payBaseBO     支付请求BO对象
     */
    public static void payBaseBOConverter(PayBaseDTO payBaseDTO, PayBaseBO payBaseBO){

        payBaseBO.setRelationNo(payBaseDTO.getRelationNo());
        payBaseBO.setRequestSystem(payBaseDTO.getRequestSystem());
        payBaseBO.setRequestBizNo(payBaseDTO.getRequestBizNo());
        payBaseBO.setRequestOrderNo(payBaseDTO.getRequestOrderNo());
        payBaseBO.setRequestDate(payBaseDTO.getRequestDate());
        payBaseBO.setRequestChannel(payBaseDTO.getRequestChannel());

        payBaseBO.setBizType(payBaseDTO.getBizType());
        payBaseBO.setSubBizType(payBaseDTO.getSubBizType());

        payBaseBO.setMerchantNo(payBaseDTO.getMerchantNo());
        payBaseBO.setServiceCode(payBaseDTO.getServiceCode());

        payBaseBO.setCcy(payBaseDTO.getCcy());
        payBaseBO.setAmt(payBaseDTO.getAmt());

        payBaseBO.setOperator(payBaseDTO.getOperator());

        payBaseBO.setDescription(payBaseDTO.getDescription());
    }

    /**
     * 支付DTO转BO
     *
     * @param payDTO    支付DTO
     * @param payBO     支付BO
     */
    public static void payDTOToBO(PayDTO payDTO, PayBO payBO) {
        payBO.setOperator(payDTO.getOperator());
        payBO.setStatus(PayStatusEnums.INIT.getCode());
        payBO.setDescription(payDTO.getDescription());
        payBO.setEventNo(payDTO.getEventNo());
        payBO.setPayeeNo(payDTO.getPayeeNo());
        payBO.setPayerAccNo(payDTO.getPayerAccNo());
        payBO.setPayerNo(payDTO.getPayerNo());
        payBO.setAmt(payDTO.getAmt());
        payBO.setBizType(payDTO.getBizType());
        payBO.setCcy(payDTO.getCcy());
        payBO.setMerchantNo(payDTO.getMerchantNo());
        payBO.setRate(new BigDecimal(payDTO.getRate()));
        payBO.setRequestBizNo(payDTO.getRequestBizNo());
        payBO.setRequestChannel(payDTO.getRequestChannel());
        payBO.setSubBizType(payDTO.getSubBizType());
        payBO.setServiceCode(payDTO.getServiceCode());
        payBO.setSourceCcy(payDTO.getSourceCcy());
        payBO.setRequestSystem(payDTO.getRequestSystem());
        payBO.setRequestDate(payDTO.getRequestDate());
        payBO.setRequestOrderNo(payDTO.getRequestOrderNo());
        payBO.setReturnUrl(payDTO.getReturnUrl());
    }

    public static SubPayBO subPayDTOToBO(FundDetailInfoDTO fundDetailInfoDTO) {
        SubPayBO subPayBO = new SubPayBO();
        subPayBO.setPayToolType(fundDetailInfoDTO.getPayToolType());
        subPayBO.setPayToolSubType(fundDetailInfoDTO.getPayToolSubType());
        subPayBO.setClassType(fundDetailInfoDTO.getPayToolSubType());
        subPayBO.setCcy(fundDetailInfoDTO.getCcy());
        subPayBO.setPayToolAmt(fundDetailInfoDTO.getPayToolAmount());
        subPayBO.setOpFlag(fundDetailInfoDTO.getOpFlag());
        subPayBO.setBankCode(fundDetailInfoDTO.getBankCode());
        subPayBO.setCardType(fundDetailInfoDTO.getCardType());
        subPayBO.setAgreeRelId(fundDetailInfoDTO.getAgreeRelId());
        subPayBO.setAgreementNo(fundDetailInfoDTO.getAgreementNo());
        subPayBO.setDescription(fundDetailInfoDTO.getDescription());
        subPayBO.setPayerAccNo(fundDetailInfoDTO.getAccountNo());
        subPayBO.setFundAmt(fundDetailInfoDTO.getBizChargeAmount());
        subPayBO.setStatus(PayStatusEnums.INIT.getCode());
        if (fundDetailInfoDTO.getFundDetailExt() != null) {
            subPayBO.setFdDtlExtra(fundDetailInfoDTO.getFundDetailExt().toString());
        }

        return subPayBO;
    }

    /**
     * 获取转账单BO
     *
     * @param baseDTO   转账请求参数DTO
     * @return              TransferBO
     */
    public static TransferBO getTransferBOByDTO(PayBaseDTO baseDTO, TransferBO transferBO) {
        if (baseDTO == null) {
            return null;
        }
        transferBO.setRelationNo(baseDTO.getRelationNo());
        transferBO.setRequestBizNo(baseDTO.getRequestBizNo());
        transferBO.setRequestDate(baseDTO.getRequestDate());
        transferBO.setRequestSystem(baseDTO.getRequestSystem());
        transferBO.setRequestOrderNo(baseDTO.getRequestOrderNo());
        transferBO.setRequestChannel(baseDTO.getRequestChannel());
        transferBO.setServiceCode(baseDTO.getServiceCode());
        transferBO.setCcy(baseDTO.getCcy());
        transferBO.setAmt(baseDTO.getAmt());
        transferBO.setSourceAmt(baseDTO.getSourceAmt());
        transferBO.setSourceCcy(baseDTO.getSourceCcy());
        transferBO.setRate(new BigDecimal(baseDTO.getRate()));
        transferBO.setBizType(baseDTO.getBizType());
        transferBO.setSubBizType(baseDTO.getSubBizType());
        transferBO.setMerchantNo(baseDTO.getMerchantNo());
        transferBO.setDescription(baseDTO.getDescription());
        transferBO.setOperator(baseDTO.getOperator());
        transferBO.setTradeLogId(MDC.get(SystemMarker.TRACE_LOG_ID));
        transferBO.setStatus(PayStatusEnums.INIT.getCode());

        return transferBO;
    }

    /**
     * 预授权单DTO转换BO
     *
     * @param authorizeDTO      预授权DTO对象
     * @param preAuthBO         预授权BO对象
     */
    public static void preAuthDTOToBO(AuthorizeDTO authorizeDTO, PreAuthBO preAuthBO){
        preAuthBO.setStatus(PayStatusEnums.INIT.getCode());
        preAuthBO.setTradeLogId(MDC.get(SystemMarker.TRACE_LOG_ID));
        preAuthBO.setPayerNo(authorizeDTO.getAuthorizeFundDTO().getPayerNo());
    }

    /**
     * 解冻体现DTO转换BO
     *
     * @param withdrawDTO      解冻提现DTO对象
     * @param preAuthBO         预授权BO对象
     */
    public static void withdrawDTOToBO(UnfreezeWithdrawDTO withdrawDTO, PreAuthBO preAuthBO){
        preAuthBO.setStatus(PayStatusEnums.INIT.getCode());
        preAuthBO.setTradeLogId(MDC.get(SystemMarker.TRACE_LOG_ID));
        //preAuthBO.setPayerNo(withdrawDTO.getAuthorizeFundDTO().getPayerNo());
    }

    /**
     * 预授权撤销单DTO转换BO
     *
     * @param cancelPayDTO      预授权撤销DTO对象
     * @param preAuthBO         预授权撤销BO对象
     */
    public static void preAuthCancelDTOToBO(CancelPayDTO cancelPayDTO, PreAuthBO preAuthBO){
        preAuthBO.setStatus(PayStatusEnums.INIT.getCode());
        preAuthBO.setTradeLogId(MDC.get(SystemMarker.TRACE_LOG_ID));
        if (StringUtils.isNotEmpty(cancelPayDTO.getOrigPayNo())){
            preAuthBO.setOrigPayNo(cancelPayDTO.getOrigPayNo());
        }
    }

    /**
     * 预授权完成单DTO转换BO
     *
     * @param authConfirmDTO        预授权完成DTO对象
     * @param preAuthBO             预授权完成BO对象
     */
    public static void preAuthConfirmDTOToBO(AuthConfirmDTO authConfirmDTO, PreAuthBO preAuthBO){
        preAuthBO.setStatus(PayStatusEnums.INIT.getCode());
        preAuthBO.setTradeLogId(MDC.get(SystemMarker.TRACE_LOG_ID));
        preAuthBO.setOrigPayNo(authConfirmDTO.getOrigPayNo());
    }

    /**
     * 预授权子单DTO对象转换BO对象
     *
     * @param authorizeDTO      预授权对象
     * @return                  BO对象
     */
    public static SubPreAuthBO subPreAuthDTOToBO(AuthorizeDTO authorizeDTO) {
        SubPreAuthBO subPreAuthBO = new SubPreAuthBO();
        AuthorizeFundDTO authorizeFundDTO = authorizeDTO.getAuthorizeFundDTO();
        subPreAuthBO.setPayToolType(authorizeFundDTO.getPayToolType());
        subPreAuthBO.setPayToolSubType(authorizeFundDTO.getPayToolSubType());
        subPreAuthBO.setPayerAccNo(authorizeFundDTO.getAccountNo());
        subPreAuthBO.setPayeeAccNo(authorizeDTO.getPayeeAccNo());
        subPreAuthBO.setAmt(authorizeFundDTO.getPayToolAmount());
        subPreAuthBO.setCcy(authorizeFundDTO.getCcy());
        subPreAuthBO.setStatus(PayStatusEnums.INIT.getCode());
        subPreAuthBO.setDescription(authorizeFundDTO.getDescription());
        subPreAuthBO.setFdDtlExtra(PaymentInfoUtils.getPaymentInfoByPay(authorizeFundDTO.getFundDetailExt()));

        return subPreAuthBO;
    }

    /**
     * 预授权子单DTO对象转换BO对象
     *
     * @param authorizeDTO      预授权对象
     * @return                  BO对象
     */
    public static SubPreAuthBO subPreAuthDTOToBO(UnfreezeWithdrawDTO authorizeDTO) {
        SubPreAuthBO subPreAuthBO = new SubPreAuthBO();
        //AuthorizeFundDTO authorizeFundDTO = authorizeDTO.getAuthorizeFundDTO();
        subPreAuthBO.setPayerAccNo(authorizeDTO.getAccountNo());
        subPreAuthBO.setCcy(authorizeDTO.getCcy());
        subPreAuthBO.setStatus(PayStatusEnums.INIT.getCode());
        subPreAuthBO.setDescription(authorizeDTO.getDescription());

        return subPreAuthBO;
    }
    /**
     * 支付查询请求DTO对象转换PayBO对象
     *
     * @param payPageQueryReqDTO        支付查询请求对象
     * @return                          PayBO对象
     */
    public static PayBO getPayBOByPayPageQueryReqDTO(PayPageQueryReqDTO payPageQueryReqDTO) {
        if (payPageQueryReqDTO == null) {
            return null;
        }
        PayBO payBO = new PayBO();
        payBO.setServiceCode(payPageQueryReqDTO.getServiceCode());
        payBO.setRelationNo(payPageQueryReqDTO.getRelationNo());
        payBO.setRequestOrderNo(payPageQueryReqDTO.getRequestOrderNo());
        payBO.setRequestBizNo(payPageQueryReqDTO.getRequestBizNo());
        payBO.setStatus(payPageQueryReqDTO.getStatus());
        payBO.setCreatedAt(payPageQueryReqDTO.getCreatedAt());
        payBO.setPayNo(payPageQueryReqDTO.getPayNo());

        return payBO;
    }

    /**
     * 支付查询请求DTO对象转换ClearDO对象
     *
     * @param payPageQueryReqDTO        支付查询请求对象
     * @return                          ClearDO
     */
    public static ClearDO getClearDOByPayPageQueryReqDTO(PayPageQueryReqDTO payPageQueryReqDTO) {
        if (payPageQueryReqDTO == null) {
            return null;
        }
        ClearDO clearDO = new ClearDO();
        clearDO.setServiceCode(payPageQueryReqDTO.getServiceCode());
        clearDO.setRelationNo(payPageQueryReqDTO.getRelationNo());
        clearDO.setRequestOrderNo(payPageQueryReqDTO.getRequestOrderNo());
        clearDO.setRequestBizNo(payPageQueryReqDTO.getRequestBizNo());
        clearDO.setStatus(payPageQueryReqDTO.getStatus());
        clearDO.setCreatedAt(payPageQueryReqDTO.getCreatedAt());
        clearDO.setPayNo(payPageQueryReqDTO.getPayNo());
        return clearDO;
    }

    /**
     * 支付查询请求DTO对象转换TransferDO对象
     *
     * @param payPageQueryReqDTO        支付查询请求对象
     * @return                          TransferDO
     */
    public static TransferDO getTransferDOByPayPageQueryReqDTO(PayPageQueryReqDTO payPageQueryReqDTO) {
        if (payPageQueryReqDTO == null) {
            return null;
        }
        TransferDO transferDO = new TransferDO();
        transferDO.setServiceCode(payPageQueryReqDTO.getServiceCode());
        transferDO.setRelationNo(payPageQueryReqDTO.getRelationNo());
        transferDO.setRequestOrderNo(payPageQueryReqDTO.getRequestOrderNo());
        transferDO.setRequestBizNo(payPageQueryReqDTO.getRequestBizNo());
        transferDO.setStatus(payPageQueryReqDTO.getStatus());
        transferDO.setCreatedAt(payPageQueryReqDTO.getCreatedAt());
        transferDO.setPayNo(payPageQueryReqDTO.getPayNo());
        return transferDO;
    }

    /**
     * 冻结单DTO转换BO
     *
     * @param freezeDTO      预授权DTO对象
     * @param freezeBO         预授权BO对象
     */
    public static void freezeDTOToBO(FreezeDTO freezeDTO, FreezeBO freezeBO){
        freezeBO.setStatus(PayStatusEnums.INIT.getCode());
        freezeBO.setAccountNo(freezeDTO.getAccountNo());
        freezeBO.setFreezeType(freezeDTO.getFreezeType());
        freezeBO.setUpdatedBy(freezeDTO.getOperator());
        freezeBO.setCreatedBy(freezeDTO.getOperator());
        freezeBO.setDealAmt(0l);
    }

    /**
     * 解冻单DTO转换BO
     *
     * @param freezeDTO      预授权DTO对象
     * @param freezeBO         预授权BO对象
     */
    public static void unfreezeDTOToBO(UnfreezeDTO freezeDTO, FreezeBO freezeBO){
        freezeBO.setStatus(PayStatusEnums.INIT.getCode());
        freezeBO.setAccountNo(freezeDTO.getAccountNo());
        freezeBO.setUpdatedBy(freezeDTO.getOperator());
        freezeBO.setCreatedBy(freezeDTO.getOperator());
        freezeBO.setOrigPayNo(freezeDTO.getOrigPayNo());
    }
}
